package object02;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @TODO
 * @Author xu
 * 2025/3/12
 */
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Phone2 {
    public static void main(String[] args) {
        String text = "你好，若有问题请及时电话联系0510-1231231或者05101112223，也可以发送邮件至123@qq.com。"
                + "若遇紧急问题，可拨打13911112222，或者18523234646。欢迎致电800-820-8820，8008208820。";

        // 正则表达式来匹配电话和邮箱
        String phonePattern = "(\\b\\d{3}-\\d{7}\\b|\\b\\d{11}\\b|\\b\\d{7,15}\\b)";
        String emailPattern = "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b";

        // 利用Pattern和Matcher来提取信息
        Pattern phone = Pattern.compile(phonePattern);
        Matcher phoneMatcher = phone.matcher(text);

        System.out.println("提取到的电话号码：");
        while (phoneMatcher.find()) {
            System.out.println(phoneMatcher.group());
        }

        Pattern email = Pattern.compile(emailPattern);
        Matcher emailMatcher = email.matcher(text);

        System.out.println("提取到的邮箱地址：");
        while (emailMatcher.find()) {
            System.out.println(emailMatcher.group());
        }
    }

}
